/*
 * Wazuh Vulnerability Scanner - Unit Tests
 * Copyright (C) 2015, Wazuh Inc.
 * September 21, 2023.
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation.
 */

#include "factoryOrchestrator_test.hpp"
#include "MockCleanAgentInventory.hpp"
#include "MockDetailsAugmentation.hpp"
#include "MockFetchAllGlobalDb.hpp"
#include "MockInventorySync.hpp"
#include "MockOsScanner.hpp"
#include "MockPackageScanner.hpp"
#include "MockQueryAllPkgsAgt.hpp"
#include "MockResultIndexer.hpp"
#include "MockSendReport.hpp"

/*
 * @brief Test the chain creation for packages.
 */
TEST_F(FactoryOrchestratorTest, TestScannerTypePackageInsert)
{
    // Create the orchestrator for PackageInsert.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::PackageInsert,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 5);
    EXPECT_EQ(context->at(0), PACKAGE_SCANNER_ID);
    EXPECT_EQ(context->at(1), DETAILS_AUGMENTATION_ID);
    EXPECT_EQ(context->at(2), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(3), SEND_REPORT_ID);
    EXPECT_EQ(context->at(4), RESULT_INDEXER_ID);
    */
}

/*
 * @brief Test the chain creation for packages.
 */
TEST_F(FactoryOrchestratorTest, TestScannerTypePackageDelete)
{
    // Create the orchestrator for PackageDelete.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::PackageDelete,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 4);
    EXPECT_EQ(context->at(0), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(1), DETAILS_AUGMENTATION_ID);
    EXPECT_EQ(context->at(2), SEND_REPORT_ID);
    EXPECT_EQ(context->at(3), RESULT_INDEXER_ID);*/
}

/*
 * @brief Test the chain creation for packages.
 */
TEST_F(FactoryOrchestratorTest, TestScannerTypeIntegrityClear)
{
    // Create the orchestrator for IntegrityClear.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::IntegrityClear,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 4);
    EXPECT_EQ(context->at(0), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(1), DETAILS_AUGMENTATION_ID);
    EXPECT_EQ(context->at(2), SEND_REPORT_ID);
    EXPECT_EQ(context->at(3), RESULT_INDEXER_ID);*/
}

/*
 * @brief Test the chain creation for os.
 */
TEST_F(FactoryOrchestratorTest, TestScannerTypeOs)
{
    // Create the orchestrator for Os.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::Os, NULL, NULL, *m_inventoryDatabase, NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 4);
    EXPECT_EQ(context->at(0), OS_SCANNER_ID);
    EXPECT_EQ(context->at(1), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(2), SEND_REPORT_ID);
    EXPECT_EQ(context->at(3), RESULT_INDEXER_ID);
    */
}

/*
 * @brief Test the chain creation for hotfixes.
 */
TEST_F(FactoryOrchestratorTest, TestScannerTypeHotfixInsert)
{
    // Create the orchestrator for HotfixInsert.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::HotfixInsert,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 3);
    EXPECT_EQ(context->at(0), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(1), SEND_REPORT_ID);
    EXPECT_EQ(context->at(2), RESULT_INDEXER_ID);*/
}

/*
 * @brief Test the chain creation for hotfixes.
 */
TEST_F(FactoryOrchestratorTest, TestScannerTypeHotfixDelete)
{
    // Create the orchestrator for HotfixDelete.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::HotfixDelete,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 3);
    EXPECT_EQ(context->at(0), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(1), SEND_REPORT_ID);
    EXPECT_EQ(context->at(2), RESULT_INDEXER_ID);
    */
}

/**
 * @brief Test the chain creation for CleanupAllData.
 */
TEST_F(FactoryOrchestratorTest, TestCreationCleanUpAllData)
{
    // Create the orchestrator for CleanUpAllDAta.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::CleanupAllData,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 1);
    EXPECT_EQ(context->at(0), CLEAN_UP_DATA_ID);
    */
}

/**
 * @brief Test the chain creation for ReScanAllAgents.
 */
TEST_F(FactoryOrchestratorTest, TestCreationReScanAllAgents)
{
    /*
    // Create the orchestrator for ReScanAllAgents.
    std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::ReScanAllAgents,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 5);
    EXPECT_EQ(context->at(0), FETCH_FROM_GLOBAL_DB_ID);
    EXPECT_EQ(context->at(1), QUERY_ALL_PACKAGES_ID);
    EXPECT_EQ(context->at(2), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(3), SEND_REPORT_ID);
    EXPECT_EQ(context->at(4), RESULT_INDEXER_ID);
    */
}

/**
 * @brief Test the chain creation for ReScanSingleAgent.
 */
TEST_F(FactoryOrchestratorTest, TestCreationReScanSingleAgent)
{
    // Create the orchestrator for ReScanSingleAgent.
    /*std::shared_ptr<AbstractHandler<std::shared_ptr<std::vector<int>>>> orchestration =
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(ScannerType::ReScanSingleAgent,
                                                       NULL,
                                                       NULL,
                                                       *m_inventoryDatabase,
                                                       NULL);

    std::shared_ptr<std::vector<int>> context = std::make_shared<std::vector<int>>();

    EXPECT_NO_THROW(orchestration->handleRequest(context));
    EXPECT_EQ(context->size(), 5);
    EXPECT_EQ(context->at(0), CLEAN_UP_DATA_ID);
    EXPECT_EQ(context->at(1), QUERY_ALL_PACKAGES_ID);
    EXPECT_EQ(context->at(2), INVENTORY_SYNC_ID);
    EXPECT_EQ(context->at(3), SEND_REPORT_ID);
    EXPECT_EQ(context->at(4), RESULT_INDEXER_ID);*/
}

/*
 * @brief Test the creation of an invalid scanner.
 */
TEST_F(FactoryOrchestratorTest, TestCreationInvalidScannerType)
{
    // Create the orchestrator with invalid ScannerType.
    /*ScannerType invalidScannerType {-1};

    try
    {
        TFactoryOrchestrator<MockPackageScanner,
                             MockDetailsAugmentation,
                             MockOsScanner,
                             MockInventorySync,
                             MockSendReport,
                             MockResultIndexer,
                             MockDatabaseFeedManager,
                             MockIndexerConnector,
                             std::vector<int>,
                             MockFetchAllGlobalDb,
                             MockCleanUpData,
                             MockQueryPkgsAgt>::create(invalidScannerType, NULL, NULL, *m_inventoryDatabase, NULL);
    }
    catch (const std::runtime_error& e)
    {
        EXPECT_STREQ(e.what(), "Invalid scanner type");
    }
    catch (...)
    {
        FAIL() << "Expected std::runtime_error";
    }*/
}
